package net.zjitc.controller;

import net.zjitc.pojo.User;
import net.zjitc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/login")
    public String login(User user, HttpSession session, Model model){
        User user1 = userService.findLogin(user.getUsername(), user.getPassword());
        if (user1!=null){
            session.setAttribute("user",user1);
            return "forward:/index.jsp";
        }else {
            model.addAttribute("msg","用户名或密码错误");
            return "login";
        }
    }
}
